﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MM.Common.DBBase;

namespace MM.Common.Base
{
    public static class IME
    {
        // Methods
        public static string GetInputCode(string source, string input_type)
        {
            string str = "";
            string commandtext = "SELECT INPUTCODE" + input_type + " FROM MXHLY_SYS_INPUTCODE WHERE CHAR_CHN = :cchar";
            for (int i = 0; i < source.Length; i++)
            {
                DataParam[] parms = new DataParam[1];
                char ch = source[i];
                parms[0] = new InputDataParam("cchar", ch.ToString());
                DataParamCol col = new DataParamCol(parms);
                object obj2 = null;
                SystemInfo.DbData.ExecuteScalar(commandtext, col, ref obj2);
                if ((obj2 != null) && !Convert.IsDBNull(obj2))
                {
                    str = str + obj2.ToString();
                }
                else
                {
                    str = str + source[i];
                }
            }
            return str;
        }

        public static string GetInputCode(string source, string input_type, int max_len)
        {
            string inputCode = GetInputCode(source, input_type);
            if (max_len > inputCode.Length)
            {
                return inputCode;
            }
            return inputCode.Substring(0, max_len);
        }

        public static void SetIme(string ime_name)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.DefaultInputLanguage;
            foreach (InputLanguage language in InputLanguage.InstalledInputLanguages)
            {
                if (language.LayoutName == ime_name)
                {
                    InputLanguage.CurrentInputLanguage = language;
                    break;
                }
            }
        }
    }
}
